home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / enhance / zbuf.doc < prev   
Text File  |  1994-08-09  |  6KB  |  152 lines

  1.     *** Adding Z Buffer output to Rayshade 4.0.6, Version 2 ***
  2.  
  3.             Mark Maimone, mwm@cs.cmu.edu
  4.  
  5.                 22 February 1994
  6.                   (orig 18 March 1992)
  7.  
  8. ==============================================================================
  9.     THIS PATCH SUPERCEDES THE ONE POSTED ON 18 MARCH 1992
  10.  
  11.     Version 2 of the Z-buffer patch has several improvements over the
  12. original.  These include:
  13.  
  14.     -- Output distance is the REAL Z coordinate now; the first release
  15.        output the distance from the eye to the object.
  16.     -- Several output formats are available; Heightfield, Text, and
  17.        Expanded text.
  18.     -- The patch is for version 4.0.6, not version 4.0.
  19.  
  20.     It's easy to use; just use the command line argument "-z", e.g.:
  21.  
  22.         rayshade -z depth.hf    ....
  23.  
  24. The default output format is HEIGHTFIELD, but you can specify a text format
  25. by using a special suffix on the filename:
  26.  
  27.         Example Filename    Output Format
  28.         ----------------    -------------
  29.         foo.hf            Heightfield
  30.         foo.txt            ASCII Text, lines correspond to rows
  31.         foo.etxt        Expanded Text, one pixel per line
  32.                     with integer coordinates, e.g.,
  33.                         1 5 3.45643
  34.  
  35.         anything else       Heightfield
  36.  
  37.     If anyone would care to provide me with a single ASCII "patch" file
  38. I'd be happy to provide it in place of the current TAR format.  I don't know
  39. the syntax required to get patch to create new files.
  40.  
  41.  
  42.  
  43. The rest of this file is a copy of the original README file, with just a few
  44. corrections.
  45.  
  46. ==============================================================================
  47.         **NOTE** This is *not* an "official" release
  48. ==============================================================================
  49.  
  50.     I've made a preliminary attempt at getting Rayshade to output depth
  51. information in addition to rendered images.  I need this information since I
  52. want to use Rayshade to generate test images for a stereo algorithm.  Having
  53. the "true" depth means I can test how accurately my stereo algorithm
  54. reconstructs it (depth) from only the stereo pair of 2D images without
  55. knowing the inherent 3D structure.
  56.  
  57.     My technique is quite basic.  I rely on the anti-aliasing scheme to
  58. sample the pixels, and remember the distance from the Eye to the nearest
  59. object along each generated ray.  Of all these distances associated with a
  60. pixel, I arbitrarily choose the one nearest to the eye to denote the "true"
  61. distance.
  62.  
  63.     This scheme has several problems (and I'm sure others will find
  64. more).  It doesn't return the distance of the object that occupies *most* of
  65. the pixel, it merely returns the distance of the object it finds nearest to
  66. the eye; it doesn't matter if it only occupies 5% of the pixel.  It lets the
  67. antialiasing scheme choose which rays are relevant; a bad antialiasing
  68. scheme may well yield a bad Z buffer.  It treats transparent objects as
  69. opaque (changing this *should* only require adding a very simple test in
  70. SampleScreen(), but I don't know enough about the internals yet).  It assumes
  71. all distances are positive (this, at least, should be a reasonable
  72. assumption).
  73.  
  74.     The changes were realized entirely within the "libshade" directory.
  75. Adding the Z buffer to rayshade involves several small changes to files in
  76. that directory, plus the addition of two more (short) source files, zbuf.c
  77. and zbuf.h.
  78.  
  79. ======== COMMAND LINE INTERFACE
  80.  
  81.     Very easy.  Just run rayshade with the "-z filename" option to write
  82. the Z buffer to the named file.  You must name some file, it won't write to
  83. stdout.
  84.  
  85. ======== IMPLEMENTATION
  86.  
  87.     Rayshade already computes everything needed to generate the Z
  88. buffer, but it throws the information away.  I've added an external Float
  89. array   (zbuffer in zbuf.c)   to store the distance to the nearest object in
  90. each pixel.  You must have enough memory available for a Float array with
  91. the same dimensions as the window being rendered.
  92.  
  93.     I put a hook into the routine where Rayshade finds the "first"
  94. object hit by a given ray (SampleScreen() in libshade/viewing.c).  That hook
  95. calls ZbufAdd() to store the current distance in global array   zbuffer.
  96. ZbufAdd() maps the Float index values to ints by using floor(pix+0.5) for
  97. both X and Y.
  98.  
  99. ======== FILE FORMAT
  100.  
  101.     Version 2 of this patch supports three output file formats.
  102.  
  103.     One is the HEIGHTFIELD format.  Please see the Rayshade guide for a
  104. description of this format.
  105.  
  106.     Another is a TEXT format.  After some opening comments, each line
  107. corresponds to a single row in the image.  Distances are represented as text
  108. (e.g. "5.45454") and separated by spaces.
  109.  
  110.     The third is an EXPANDED TEXT format.  The first few lines in the
  111. file are comments describing the source of the data.  After that, the depth
  112. information follows, with each line representing a single pixel:
  113.  
  114.     <int x-coord> <int y-coord> <Float distance>
  115.  
  116. A distance of -1000 means the pixel denotes background.  The file is ordered
  117. by scanline, with a blank line separating scanlines.  This format is ideally
  118. suited for viewing the depth map using GNUplot (see comments in zbuf.c).
  119.  
  120.     Here's a sample output file:
  121.  
  122. # Depth Map for Rayshade output file
  123. # Input RAY file: "../Examples/planet.ray"
  124. # Resolution for this rendering is 50x50
  125. # window from (0,0) to (49,49)
  126. # Index 0: 11412 hits
  127. 0 0 -1
  128. 0 1 -1
  129. 0 2 -1
  130. 0 3 -1
  131.     .        [ I deleted many lines for brevity ]
  132.     .
  133. 12 13 -1
  134. 12 14 -1
  135. 12 15 -1
  136. 12 16 3.75485
  137. 12 17 3.60294
  138. 12 18 3.52262
  139. 12 19 3.46714
  140. 12 20 3.42647
  141. 12 21 3.40308
  142.  
  143. ======== COMMENTS
  144.  
  145.     Please post any comments to the rayshade-users@cs.princeton.edu
  146. mailing list, or if you prefer you may send them directly to me at
  147. mwm@cs.cmu.edu.  Any comments are welcome...
  148.  
  149.                     Mark Maimone
  150.                     CMU Computer Science
  151.                     mwm@cs.cmu.edu
  152.